<template>
	<view>
		<view class="p-10">
			<view class="p-10 bg-white">
				<view v-if="!is_iframe" class="banmi_flex a-c j-c" style="height: 80vh;">
					<image class="weisubao-loading-img" src="@/static/lo.gif"></image>
				</view>

				<iframe :class="is_iframe?'':'v-hidden'" id="zen_iframe" name="zen_iframe" width="100%"
					:style="'height:'+ windowHeight + 'px;'" :src="url" frameborder="0"></iframe>

			</view>
		</view>
	</view>
</template>

<script>
	import $C from '@/common/banmi/config.js';
	export default {
		data() {
			return {
				url: '',
				windowHeight: 0,
				time: 0,
				id: 0,
				is_iframe: false
			}
		},
		onLoad(on) {
			let that = this;
			this.id = on.id;

			this.time = new Date().getTime();
			this.windowHeight = uni.getSystemInfoSync().windowHeight - 60;
			var plugin_url = '';
			var catalogue = '';
			var plugin_id = 0;
			var menu_list = uni.getStorageSync('menu_list');

			for (var i = 0; i < menu_list.length; i++) {
				if (menu_list[i]['menu_id'] == on.id) {
					plugin_url = menu_list[i]['url']
					catalogue = menu_list[i]['plugin_catalogue']
					plugin_id = menu_list[i]['plugin_id']
				}
			}
			var key = document.getElementById('get_admin').getAttribute("admin_key");
			var admin_888 = document.getElementById('get_admin').getAttribute("admin_888");
			if (key != '{$admin_key}') {
				var banmi_admin_key = key;
			} else {
				var banmi_admin_key = ADMINKEY;
			}
			var admin_token = uni.getStorageSync('admin_token');
			var home_url = window.location.protocol + '//' + window.location.host;

			var route = '/' + admin_888 + '/zenkuai/' + catalogue + '/' + '?time=' + this.time + '&banmi_admin_key=' +
				banmi_admin_key + '&token=' +
				admin_token + '&admin_token=' +
				admin_token + '#/' +
				plugin_url + '?banmi_plugin=' + this.id + '&catalogue=' + catalogue;
			route = route.replace("//", "/");
			this.url = home_url + route
			this.Test();
		},

		methods: {
			Test() {
				const self = this
				this.$nextTick(() => {
					const iframe = document.querySelector('#zen_iframe')
					if (iframe.attachEvent) {
						iframe.attachEvent("onload", function() {
							setTimeout(function() {
								self.is_iframe = true
							}, 300);
						});
					} else {
						iframe.onload = function() {
							setTimeout(function() {
								self.is_iframe = true
							}, 300);
						};
					}
				})
			}

		}
	}
</script>

<style>
	.weisubao-loading-img {
		width: 100rpx;
		height: 100rpx;
	}

	.v-hidden {
		visibility: hidden
	}
</style>